//
//  SCPersonCenterController.m
//  Mutal
//
//  Created by TonyStart on 16/10/18.
//  Copyright © 2016年 com.wx. All rights reserved.
//

#import "SCPersonCenterController.h"
#import "SCPersonCenterButton.h"
#import "SCUserInfo.h"
#import "SCUserInfoModel.h"
@interface SCPersonCenterController ()
@property (weak, nonatomic) IBOutlet UIButton *picBtn;
@property (weak, nonatomic) IBOutlet UILabel *userNiceName;

@end
#define BUTTON_HEIGHT 40
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size
@implementation SCPersonCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:YES];
    
    
}

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    [self setupUI];
    
}
-(void)setupUI{
    self.picBtn.layer.cornerRadius = 30;
    self.picBtn.layer.masksToBounds = YES;
    //判断是否有登录
    BOOL isLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"is_login"];
    if (isLogin) {
        //判断用户信息单例内是否有保存数据
        SCUserInfo *userInfo = [SCUserInfo defaultUser];

        if (!userInfo.userInfo) {
            //如果单例内种没有数据 就从Plist中取出来 然后给单例赋值
            NSDictionary *userInfo = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingString:@"/Documents/userInfo.plist"]];
            [SCUserInfo defaultUser].userInfo = [SCUserInfoModel userInfoWithDict:userInfo];
            
        }
  
        NSString *imgPath =[NSString stringWithFormat:@"%@%@",[NSHomeDirectory() stringByAppendingString:@"/Documents/"],userInfo.userInfo.avatar] ;
    
        //间用户单例信息 给控件赋值
        [_picBtn setImage:[UIImage imageWithContentsOfFile:imgPath] forState:UIControlStateNormal];
        _userNiceName.text = userInfo.userInfo.user_nicename;
    }
    
    [self setupButtons];
}
-(void)setupButtons{
    SCPersonCenterButton *wishNumBtn = [[SCPersonCenterButton alloc] initWithFrame:CGRectMake(0, 190, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-愿望次数" title:@"愿望次数" rightIconStr:@"icon-right"];
    UIView *speatorView = [[UIView alloc] initWithFrame:CGRectMake(50, 230, SCREEN_SIZE.width, 1)];
    speatorView.backgroundColor = [UIColor grayColor];
    
    SCPersonCenterButton *walletBtn = [[SCPersonCenterButton alloc] initWithFrame:CGRectMake(0, 230, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-钱包" title:@"钱包" rightIconStr:@"icon-right"];
    
    [self.view addSubview:wishNumBtn];
    [self.view addSubview:walletBtn];
    [self.view addSubview:speatorView];
    
    SCPersonCenterButton *aboutUSBtn = [[SCPersonCenterButton alloc] initWithFrame:CGRectMake(0, 280, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-关于我们" title:@"关于我们" rightIconStr:@"icon-right"];
    SCPersonCenterButton *commentsBtn = [[SCPersonCenterButton alloc] initWithFrame:CGRectMake(0, 320, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-反馈" title:@"建议反馈" rightIconStr:@"icon-right"];
    SCPersonCenterButton *settingBtn = [[SCPersonCenterButton alloc] initWithFrame:CGRectMake(0, 360, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-设置" title:@"设置" rightIconStr:@"icon-right"];
    UIView *speatorView2 = [[UIView alloc] initWithFrame:CGRectMake(50, 320, SCREEN_SIZE.width, 1)];
    speatorView2.backgroundColor = [UIColor grayColor];
    UIView *speatorView3 = [[UIView alloc] initWithFrame:CGRectMake(50, 360, SCREEN_SIZE.width, 1)];
    speatorView3.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:aboutUSBtn];
    [self.view addSubview:commentsBtn];
    [self.view addSubview:settingBtn];
    [self.view addSubview:speatorView2];
    [self.view addSubview:speatorView3];
    
    
}

- (IBAction)wishBtnClick:(id)sender {
}
- (IBAction)rewardBtnClick:(id)sender {
}
- (IBAction)collectionBtnClick:(id)sender {
}

- (IBAction)picBtnClick:(id)sender {
}

@end
